package com.controller.lx;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.entity.Function;
import com.service.ServiceException;
import com.service.lx.FunctionService;
import com.utils.Result;

@Controller
public class FunctioController {
	@Autowired
	private FunctionService functionService;

	/**
	 * 查询用户
	 * @return
	 */
	@PostMapping("/function_select_")
	@ResponseBody
	public Page<Function> findAll(@RequestParam("field") String field, 
			@RequestParam("curpage") Integer curpage, 
			@RequestParam("pagesize") Integer pagesize){
		return functionService.findUsersBy(field, curpage, pagesize);
	}
	
	/**
	 * 逻辑删除
	 * @param Id
	 * @throws ServiceException
	 */
	@DeleteMapping("/function_ifdelete_")
	@ResponseBody
	public Result UpdateIfdelete(Long Id){
		functionService.UpdateFunctionIfdelete(Id);
		return Result.SUCCESS;
	}

	/**
	 * 批量删除
	 * @param qaIds
	 */
	@PostMapping("/function_delete_arr_")
	@ResponseBody
	public Result deletBatchRoles(@RequestBody JSONArray Ids) {
		functionService.deletArrIfDelete(JSONObject.parseArray(Ids.toString(), Long.class));
		return Result.SUCCESS;
	}

	/**
	 * 添加/修改
	 * @param serve
	 * @throws ServiceException
	 */
	@PostMapping("/function_addandupdate_")
	@ResponseBody
	public Result addAndUpdate(@RequestBody Function function){
		functionService.addAndUpdateFunction(function);
		return Result.SUCCESS;
	}
}
